package com.mindainfo.groundwave.server.base.config;

import com.mindainfo.groundwave.server.base.component.GlobalParams;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import javax.annotation.Resource;

/**
 * Created by MD-01 on 2017/5/3.
 */
@Configuration
public class RedisConfig {

    @Resource
    private GlobalParams globalParams;

    @Bean
    public JedisPool jedisPool(){

        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(150);
        config.setTestOnBorrow(true);
        config.setMaxWaitMillis(3000);
        GlobalParams.RedisParams redis = globalParams.getRedis();

        JedisPool pool = new JedisPool(config,
                redis.getHost(),
                redis.getPort(),
                3000,
                redis.getPassword());
        return pool;
    }
}
